package xxy.com.yangproject.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;

import java.lang.ref.WeakReference;

import xxy.com.yangproject.R;
import xxy.com.yangproject.global.Constant;

public class NavigationChildAdapter extends RecyclerView.Adapter<NavigationChildAdapter.NavigationChildViewHolder> {

    private final WeakReference<Activity> activityWeakReference;
    private final int position;

    public NavigationChildAdapter(final Activity activity, final int position) {
        this.activityWeakReference = new WeakReference<>(activity);
        this.position = position;
    }

    @NonNull
    @Override
    public NavigationChildViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LogUtils.eTag(Constant.TAG_LOOP, "onCreateViewHolder : " + position);
      return new NavigationChildViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.rv_navigation_child, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull NavigationChildViewHolder holder, int position) {
        if (position % 2 == 0) {
            holder.textView.setText("odd");
        } else {
            holder.textView.setText("even");
        }
        LogUtils.eTag(Constant.TAG_LOOP, "onBindViewHolder : " + position);
    }

    @Override
    public int getItemCount() {
        return 6;
    }

    @Override
    public int getItemViewType(int position) {
        return  1;
    }

    public static class NavigationChildViewHolder extends RecyclerView.ViewHolder {

        private final AppCompatTextView textView;

        public NavigationChildViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv_navigation_child);
        }
    }
}
